home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dviselect / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  2.0 KB  |  95 lines

  1. /*
  2.  * Copyright (c) 1987 University of Maryland Department of Computer Science.
  3.  * All rights reserved.  Permission to copy for any purpose is hereby granted
  4.  * so long as this copyright notice remains intact.
  5.  */
  6.  
  7. #ifndef lint
  8. static char rcsid[] = "$Header: /sprite/src/cmds/dviselect/RCS/error.c,v 1.1 91/10/18 21:15:45 rab Exp Locker: rab $";
  9. #endif
  10.  
  11. /*
  12.  * Print an error message with an optional system error number, and
  13.  * optionally quit.
  14.  *
  15.  * THIS CODE IS SYSTEM DEPENDENT UNLESS varargs WORKS WITH vprintf
  16.  * OR _doprnt.  It should work properly under System V using vprintf.
  17.  * (If you have vprintf, define HAVE_VPRINTF.)
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <varargs.h>
  22.  
  23. #ifdef lint
  24.  
  25. /* VARARGS3 ARGSUSED */
  26. error(quit, e, fmt) int quit, e; char *fmt; {;}
  27.  
  28. /* VARARGS1 ARGSUSED */
  29. panic(fmt) char *fmt; { exit(1); /* NOTREACHED */ }
  30.  
  31. #else lint
  32.  
  33. extern char *ProgName;
  34. extern int errno;
  35. extern char *sys_errlist[];
  36. extern int sys_nerr;
  37.  
  38. error(va_alist)
  39.     va_dcl
  40. {
  41.     va_list l;
  42.     int quit, e;
  43.     char *fmt;
  44.  
  45.     (void) fflush(stdout);    /* sync error messages */
  46.     (void) fprintf(stderr, "%s: ", ProgName);
  47.     va_start(l);
  48.     /* pick up the constant arguments: quit, errno, printf format */
  49.     quit = va_arg(l, int);
  50.     e = va_arg(l, int);
  51.     if (e < 0)
  52.         e = errno;
  53.     fmt = va_arg(l, char *);
  54. #if defined(sys5) || defined(HAVE_VPRINTF)
  55.     (void) vfprintf(stderr, fmt, l);
  56. #else
  57.     _doprnt(fmt, l, stderr);
  58. #endif
  59.     va_end(l);
  60.     if (e) {
  61.         if (e < sys_nerr)
  62.             (void) fprintf(stderr, ": %s", sys_errlist[e]);
  63.         else
  64.             (void) fprintf(stderr, ": Unknown error code %d", e);
  65.     }
  66.     (void) putc('\n', stderr);
  67.     (void) fflush(stderr);    /* just in case */
  68.     if (quit)
  69.         exit(quit);
  70. }
  71.  
  72. panic(va_alist)
  73.     va_dcl
  74. {
  75.     va_list l;
  76.     char *fmt;
  77.  
  78.     (void) fflush(stdout);
  79.     (void) fprintf(stderr, "%s: panic: ", ProgName);
  80.     va_start(l);
  81.     /* pick up the constant argument: printf format */
  82.     fmt = va_arg(l, char *);
  83. #if defined(sys5) || defined(HAVE_VPRINTF)
  84.     (void) vfprintf(stderr, fmt, l);
  85. #else
  86.     _doprnt(fmt, l, stderr);
  87. #endif
  88.     va_end(l);
  89.     (void) putc('\n', stderr);
  90.     (void) fflush(stderr);
  91.     abort();
  92. }
  93.  
  94. #endif /* lint */
  95.